import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/router_config.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/custom_button.dart';
import 'package:s_mankey/ui/widget/error_widget.dart';
import 'package:s_mankey/ui/widget/loading_widget.dart';
import 'package:s_mankey/ui/widget/unlogin_nav.dart';

class SystemMsgDetail extends StatefulWidget {

  final arguments;

  SystemMsgDetail({this.arguments});

  @override
  _SystemMsgDetail createState() => _SystemMsgDetail();
}

class _SystemMsgDetail extends State<SystemMsgDetail>{

  var datas;
  Map<String, dynamic> options = Map();
  Map<String, dynamic> nextOptions = Map();

  @override
  void initState() {

    print('widget.arguments${widget.arguments}');
    if(widget.arguments != null){
      options['id'] = widget.arguments['id'];
      nextOptions['id'] = widget.arguments['cid'];
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        title: Text('消息详情'),
      ),
      body: FutureBuilder(future: SmonkeysRepository.fetchNotifyDetail(options: options),builder:
    (BuildContext context, AsyncSnapshot snapshot) {

    /// 请求中
    if (snapshot.connectionState != ConnectionState.done) {
    return LoadingWidget();
    }
    /// 请求结束
    if (snapshot.hasError) {
    // 请求失败，显示错误
    return datasErrorWidget(errorTip: snapshot.error.toString(),);
    }

    datas = snapshot.data;
    print('datas##${datas}');
    // 请求成功，显示数据
    return

      Container(
        child: Column(
          children: [
            //标题
            Container(
              padding: EdgeInsets.fromLTRB(0, 20, 0, 10),
              child: Text(
                datas['template_name'],
//                '123',
                style: TextStyle(fontSize: AppFontSize.Size22),
              ),
              
            ),

            Container(
              padding: EdgeInsets.fromLTRB(15, 10, 15, 20),
              decoration: BoxDecoration(
                  border:
                  Border(bottom: BorderSide(color: AppColor.dividerColor))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      ClipOval(clipBehavior: Clip.antiAlias,child: Image.network(
                        'https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2319772070,3114389419&fm=26&gp=0.jpg',fit: BoxFit.fill,
                        width: 40,
                        height: 40,
                      ),),

                      Padding(
                        padding: const EdgeInsets.only(left: 10),
                        child: Text('系统消息',style: TextStyle(color: Color(0xff909090)),),
                      ),
                    ],
                  ),
                  Text((datas['create_time']).toString(),style: TextStyle(color: Color(0xff909090)),),
                ],
              ),
            ),

            Container(
              alignment: Alignment(-1,0),
              padding: EdgeInsets.fromLTRB(15, 20, 15, 0),
              child:
              Text((datas['message']).toString(),style: TextStyle(color: Colors.black,fontSize: AppFontSize.Size18),),

            ),

            Offstage(offstage: (datas['is_nvitation'] != 1),child:
            GestureDetector(onTap: (){
              ///TODO: 这里的跳转还没有做
              Navigator.pushNamed(context, RouterName.inviteDetail, arguments: nextOptions['id']);
            },child: CustomButton(
                margin: EdgeInsets.only(top: 30),
                padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
                widgt: 250.0,
                title: '前往课程详情',
                fontSize: AppFontSize.Size18,
                fontColor: Colors.white,
                radius: 30.0,
                borderColor: Colors.transparent,
                gradient: AppColor.gradientColorHigh),),),
            

          ],
        ),
      );}),
    );
  }

}
